package Test_2019_3_19.servlet;

import Test_2019_3_19.pojo.User;
import Test_2019_3_19.util.JdbcUtil;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "AddSelectServlet",urlPatterns = {"/atb/addSelect.do"})
public class AddSelectServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //get解决中文乱码
        response.setContentType("application/text; charset=utf-8");
        // 阿里巴巴druid连接数据库
        JdbcUtil jdbc = new JdbcUtil();
        // 遍历结果集
        List<User> att = jdbc.find();
        Map<String, Object> mjs = new HashMap<String, Object>();
        mjs.put("code",0);
        mjs.put("msg","");
        mjs.put("count",jdbc.findCount());
        mjs.put("data",att);
        // 把数据转化为json格式
        String Json = JSON.toJSONString(mjs);
        response.getWriter().write(Json);
    }
}